<template>
  <div class="loginContent">
    <div class="title">湖州市应急综合监管平台</div>
    <el-form
      :model="ruleForm"
      status-icon
      :rules="rules"
      ref="ruleForm"
      class="login_form"
    >
      <div class="form_title">密码登录</div>
      <div class="formGang"></div>
      <el-form-item prop="phone">
        <el-input
          type=""
          placeholder="用户名"
          v-model.number="ruleForm.phone"
          autocomplete="off"
        ></el-input>
      </el-form-item>
      <el-form-item prop="checkPass">
        <el-input
          type="password"
          placeholder="请输入密码"
          v-model="ruleForm.checkPass"
          autocomplete="off"
        ></el-input>
      </el-form-item>

      <el-form-item>
        <el-button
          type="primary"
          style="width: 290px; height: 40px; background: #2fc4b2"
          @click="submitForm('ruleForm')"
          >提交</el-button
        >
      </el-form-item>
    </el-form>

    <div class="copyright">
      Copyright © 2023 浙江领卓智慧科技有限公司 版权所有 浙ICP备01108888 号
    </div>
  </div>
</template>

<script>
import { newLogin } from '@/api/login'

export default {
  name: 'loginPage',
  props: {},
  components: {},
  data() {
    // var checkNumber = (rule, value, callback) => {
    //   if (!value) {
    //     return callback(new Error('不能为空'))
    //   }
    //   setTimeout(() => {
    //     if (!Number.isInteger(value)) {
    //       callback(new Error('请输入数字'))
    //     } else {
    //       callback()
    //     }
    //   }, 500)
    // }
    return {
      ruleForm: {
        phone: '',
        checkPass: '',
      },
      rules: {
        phone: [{ required: true, trigger: 'change' }],
        checkPass: [{ required: true, message: '请输入密码', trigger: 'blur' }],
      },
    }
  },
  methods: {
    async userLogin() {
      const res = await newLogin({
        username: this.ruleForm.phone,
        password: this.ruleForm.checkPass,
      })

      if (res.code === 200) {
        this.$store.commit('user/setToken', res.data)
        this.$message.success('登录成功')
        const vuexValue = JSON.parse(localStorage.getItem('vuexRoleList'))
        this.$store.dispatch('user/roleListFunction', vuexValue.roleId)
        this.$router.push('/index')
      } else {
        this.$message.error('登录失败，请稍后重试')
      }
    },
    async submitForm(formName) {
      this.$refs[formName].validate((valid) => {
        if (valid) {
          this.userLogin()
        } else {
          this.$message.error('登录失败，请稍后重试1')
          return false
        }
      })
    },
  },
  created() {},
  mounted() {},
  watch: {},
  computed: {},
  filters: {},
}
</script>

<style scoped lang="scss">
.loginContent {
  width: 1920px;
  height: 1080px;
  position: relative;
  background-image: url('@/assets/login/Background.png');
  background-size: cover;
  background-repeat: no-repeat;
  position: relative;
  font-family: 思源黑体;

  .login_form {
    position: absolute;
    left: 760px;
    top: 330px;
    width: 400px;
    height: 420px;
    border-radius: 20px;
    opacity: 1;
    background: #ffffff;
    box-shadow: 0px 10px 35px 0px rgba(0, 0, 0, 0.1);
    padding: 92px 55px;
    box-sizing: border-box;

    .form_title {
      width: 145px;
      height: 35px;
      text-align: center;
      font-family: 思源黑体;
      font-size: 16px;
      font-weight: 500;
      line-height: 19px;
      color: #2fc4b2;
      border-bottom: 3px solid #2fc4b2;
      margin-left: 72px;
    }
    .formGang {
      width: 290px;
      height: 1px;
      background: #dcdfe6;
      margin-bottom: 40px;
    }
  }

  .title {
    width: 100%;
    font-size: 40px;
    font-weight: 500;
    line-height: normal;
    text-align: center;
    color: #ffffff;
    position: absolute;
    top: 232px;
  }
  .copyright {
    width: 100%;
    text-align: center;
    color: #ffffff;
    font-size: 12px;
    line-height: 14px;
    position: absolute;
    bottom: 60px;
    left: 0;
  }
}
</style>
